from django.contrib import admin
from goods import models
from celery_tasks.static_html.tasks import generate_static_list_search_html, generate_static_sku_detail_html

# Register your models here.
class GoodsModelAdmin(admin.ModelAdmin):
    list_display = ['id', 'name']


class GoodsCategoryModelAdmin(admin.ModelAdmin):

    list_per_page = 10

    def save_model(self, request, obj, form, change):
        obj.save()

        generate_static_list_search_html.delay()


class SKUModelAdmin(admin.ModelAdmin):
    def save_model(self, request, obj, form, change):
        obj.save()
        generate_static_sku_detail_html.delay(obj.id)

admin.site.register(models.Goods, GoodsModelAdmin)
admin.site.register(models.GoodsCategory, GoodsCategoryModelAdmin)
admin.site.register(models.GoodsChannel)
admin.site.register(models.Brand)
admin.site.register(models.GoodsSpecification)
admin.site.register(models.SpecificationOption)
admin.site.register(models.SKU, SKUModelAdmin)
admin.site.register(models.SKUSpecification)
admin.site.register(models.SKUImage)